package bsh.dyn;

/**
 * A {@link DeclaredParameterType} that is a reference - as opposed to a primitive
 * 
 * @author takeshi
 */
public class ReferenceDeclaredType extends AbstractReferenceParameter implements DeclaredParameterType {

    private final Class<?> javaType;

    /**
     * Ctor
     * 
     * @param javaType the java type
     */
    public ReferenceDeclaredType(Class<?> javaType) {
        super();
        this.javaType = javaType;
    }

    /**
     * {@inheritDoc}
     */
    public Class<?> getJavaType() {
        return javaType;
    }

    /**
     * {@inheritDoc}
     */
    public boolean acceptsNull() {
        return true;
    }

    /**
     * {@inheritDoc}
     */
    public DeclaredParameterType getComponentType() {
        if (this.isArray()) {
            if (getJavaType().getComponentType().isPrimitive()) {
                return new PrimitiveParameter(getJavaType().getComponentType());
            } else {
                return new ReferenceDeclaredType(getJavaType().getComponentType());
            }
        }
        return null;
    }

    /**
     * {@inheritDoc}
     */
    public boolean isArray() {
        return getJavaType().isArray();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return "ReferenceDeclaredType [javaType=" + javaType + "]";
    }

}
